package com.moon.interview.controller;

import com.moon.interview.common.BaseResponse;
import com.moon.interview.common.ResultUtils;
import com.moon.interview.exception.SysErrorCode;
import com.moon.interview.exception.ApplicationException;
import com.moon.interview.model.dto.questionBankQuestion.QuestionBankQuestionBatchRequest;
import com.moon.interview.model.dto.questionBankQuestion.QuestionBankQuestionRequest;
import com.moon.interview.model.vo.QuestionBankQuestionVo;
import com.moon.interview.service.IQuestionBankQuestionService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 题目(QuestionBankQuestion)表控制层
 *
 * @author MoonX
 * @since 2025-03-17 20:05:37
 */
@RestController
@RequestMapping("questionBankQuestion")
public class QuestionBankQuestionController {
    /**
     * 服务对象
     */
    @Resource
    private IQuestionBankQuestionService questionBankQuestionService;

    /**
     * 添加题目题库关联信息
     */
    @PostMapping("/add")
    public BaseResponse<Boolean> addQuestionBankQuestion(@RequestBody QuestionBankQuestionRequest addRequest) {
        if (addRequest == null) {
            throw new ApplicationException(SysErrorCode.PARAMS_ERROR);
        }
        return ResultUtils.success(questionBankQuestionService.addQuestionBankQuestion(addRequest));
    }

    /**
     * 更新题目题库关联信息
     * @param updateRequest 更新请求参数
     * @return boolean
     */
    @PostMapping("/update")
    public BaseResponse<Boolean> updateQuestionBankQuestion(@RequestBody QuestionBankQuestionRequest updateRequest) {
        if (updateRequest == null) {
            throw new ApplicationException(SysErrorCode.PARAMS_ERROR);
        }
        return ResultUtils.success(questionBankQuestionService.updateQuestionBankQuestion(updateRequest));
    }

    /**
     * 批量添加题目题库关联信息
     * @param batchRequest 批量添加请求参数
     * @return boolean
     */
    @PostMapping("/batch")
    public BaseResponse<Boolean> addBatchQuestionBankQuestion(@RequestBody QuestionBankQuestionBatchRequest batchRequest) {
        if (batchRequest == null) {
            throw new ApplicationException(SysErrorCode.PARAMS_ERROR);
        }
        return ResultUtils.success(questionBankQuestionService.addBatchQuestionBankQuestion(batchRequest));
    }

    /**
     * 根据题目ID获取题目题库关联信息
     * @param questionId 题目id
     * @return List<QuestionBankQuestionVo>
     */
    @GetMapping("/getBankList")
    public BaseResponse<List<QuestionBankQuestionVo>> getBankList(Long questionId) {
        if (questionId == null) {
            throw new ApplicationException(SysErrorCode.PARAMS_ERROR);
        }
        return ResultUtils.success(questionBankQuestionService.getQuestionBankByQuestionId(questionId));
    }

    /**
     * 根据题库Id移除题目题库关联信息
     * @param bankId
     * @return
     */
    @GetMapping("/removeQuestion")
    public BaseResponse<Boolean> removeQuestionByBankId(Long bankId) {
        if (bankId == null) {
            throw new ApplicationException(SysErrorCode.PARAMS_ERROR);
        }
        return ResultUtils.success(questionBankQuestionService.removeQuestionByBankId(bankId));
    }
}

